home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Harmless / Fred / Source / MyView.m < prev    next >
Encoding:
Text File  |  1993-01-26  |  1.8 KB  |  99 lines

  1. /*     
  2.  
  3.     Fred 
  4.  
  5.     Implementation
  6.  
  7.     Created:          November 1991
  8.     Last Edited:        April 1992
  9.     
  10.     Sean Luke
  11.     
  12.     Modified    Todd Anthony Nathan
  13.             April 10, 1992
  14.             Cleaned up code, and got slider to work
  15.     
  16. */
  17.  
  18.  
  19. #import "MyView.h"
  20. #define    DISTANCE    2.0
  21.  
  22. @implementation MyView
  23.  
  24. // Prototypes
  25. DPSTimedEntryProc movewindow(DPSTimedEntry teNum,double now, void* TheWindow);
  26.  
  27. - appDidInit:sender
  28. // Init some things for later use.
  29. {
  30.     interval    = 0.5;
  31.     priority    = NX_RUNMODALTHRESHOLD;
  32.     thisWindow    = [NXApp appIcon];
  33.     // put in the first timed entry...
  34.     teNum        = DPSAddTimedEntry((double) interval, (DPSTimedEntryProc) movewindow,
  35.                 (void*) thisWindow, (int) priority);
  36.             
  37.     return self;
  38.     
  39. }
  40.  
  41.  
  42. - appWillTerminate:sender
  43. // Clean up and go home when user quits
  44. {
  45.     if (teNum) DPSRemoveTimedEntry(teNum);
  46.     
  47.     return self;
  48.     
  49. }
  50.  
  51.  
  52. - changeSpeed:sender
  53. {
  54.     interval = [theSlider floatValue];
  55.     printf("The slider value is = %f\n", interval);
  56.     if (teNum) DPSRemoveTimedEntry(teNum);
  57.     teNum = DPSAddTimedEntry((double) interval, (DPSTimedEntryProc) movewindow,
  58.             (void*) thisWindow, (int) priority);
  59.             
  60.     return self;
  61.     
  62. }
  63.     
  64.     
  65. DPSTimedEntryProc movewindow(DPSTimedEntry teNum,double now, void* TheWindow)
  66. {
  67.     id    theWindow;
  68.     int    z;
  69.     float    x,
  70.         y,
  71.         a,
  72.         b,
  73.         width,
  74.         height,
  75.         angle;
  76.     NXPoint    ThePoint;
  77.     NXRect    TheRect;
  78.     
  79.     for (z = 0 ; z <= 20 ; z++) {
  80.         theWindow = (id)TheWindow;
  81.         [theWindow getMouseLocation:&ThePoint];
  82.         x = ThePoint.x;
  83.         y = ThePoint.y;
  84.         [theWindow getFrame: &TheRect];
  85.         a = TheRect.origin.x;
  86.         b = TheRect.origin.y;
  87.         width = TheRect.size.width;
  88.         height = TheRect.size.height;
  89.         angle = atan2( y - height / 2.0, x - width / 2.0);
  90.         if ((x + y - height / 2.0 - width / 2.0 > 1.5) || (x + y - height / 2.0 - width / 2.0 < - 1.5))
  91.              [theWindow moveTo:DISTANCE * cos(angle) + a :DISTANCE * sin(angle) + b];
  92.     }
  93.  
  94.     return (void*) NULL;
  95.  
  96. }
  97.  
  98. @end
  99.